package main;
import java.io.IOException;


public class Main {
	private static final long  MEGABYTE = 1024L * 1024L;

	/**
	 * The main method.
	 * 
	 * @param args the arguments
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws ParserConfigurationException 
	 * @throws XPathExpressionException 
	 */
	public static void main(String[] args){
		long startTime = System.nanoTime();
		long endTime;
		if (args.length>1){
			String file;
			if (args.length>2){
				file=args[2];
			}else file="";
			SaxParser parser = new SaxParser(args[0],args[1],file);
			parser.readFile();
			endTime = System.nanoTime();
			long duration = endTime - startTime;
			double durationInSec=(double)duration/1000000000.0;
			System.out.println("\nDocument sax parsed in "+duration+" ns ("+durationInSec+" s)\n");
			// Get the Java runtime
			Runtime runtime = Runtime.getRuntime();
			// Run the garbage collector
			runtime.gc();
			// Calculate the used memory
			long memory = runtime.totalMemory() - runtime.freeMemory();
			System.out.println("Used memory is bytes: " + memory);
			System.out.println("Used memory is megabytes: "
					+ memory/MEGABYTE);
		}
		else System.out.println("You must provide an xml file, an xPath expression and a file location to save the output! ");
	}	
}